package ws.jdbc.concurrent.driver.sqlserver

import java.nio.ByteBuffer
import java.nio.charset.*
import ws.utils.ArrayUtil

/**
 *
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
class TestZone extends GroovyTestCase {
	public void testByteBuffer() {
    ByteBuffer data = ByteBuffer.allocate(4);
    ArrayUtil.printHex(data.putInt(524).array())
    println "int = " + data.getInt(0)
  }

  public void Connection() {
    println "testConnection"
    java.sql.Connection con = java.sql.DriverManager.getConnection("jdbc:sqlserver://goldberg-wm:1433;"
          + "user=sa;password=sg4765j;")

    assertNotNull con
  }

  public void testStringBytes() {
    println "testStringBytes()"
    print "s="
    for(Byte b : "wilson".getBytes("UTF-16BE")) {
      print b + ", "
    }
  }

  public void testPrintAvailableCharsets() {
    println "printAvailableCharsets()"
    SortedMap map = Charset.availableCharsets()
    println map
  }

  void testDataStreams() {
    println "testDataStreams()"

    def port = 5454

    Thread.start {
      def ios = new ServerSocket(port).accept()
      println "Accepted!"
      def os = new DataOutputStream(new BufferedOutputStream(ios.getOutputStream()))
      os.writeInt(50)
      os.flush()
      println "Int written!"
    }

    def sock = new Socket("localhost", port)    
    def is = new DataInputStream(new BufferedInputStream(sock.getInputStream()))
    
    println "Int=" + is.readInt()
  }
}

